<template>
	<div class="h-full overflow-hidden">
		<t-tree
		:data="itemEnd"
		expandAll
		activable
		hover
		transition
		@click="onClick"
		:actived="valueArr"
		/>
	</div>
</template>

<script>
	export default {
		name: 'UserInfoItem',
		computed: {
			itemEnd(){
				let data = []
				let items = [{ value: 0, label: '贝德米数字传媒'}]
				let userArr = this.$store.state.user.userInfoAll
				let departmentArr = this.$store.state.user.departmentInfo
				for(let i = 0 ; i < departmentArr.length ; i++){
					data[i] = {}
					data[i].value = departmentArr[i].department_id
					data[i].label = departmentArr[i].department_name
					data[i].children = []
				}
				for(let i = 0 ; i < data.length ; i++){
					let index = 0
					for(let j = 0 ; j < userArr.length ; j++){
						if(this.$store.state.user.userStateValue){
							if(data[i].value === userArr[j].department_id && userArr[j].state != 2){
								data[i].children[index] = {}
								data[i].children[index].value = userArr[j].id
								data[i].children[index].label = userArr[j].name
								index++
							}
						} else {
							if(data[i].value === userArr[j].department_id){
								data[i].children[index] = {}
								data[i].children[index].value = userArr[j].id
								data[i].children[index].label = userArr[j].name
								index++
							}
						}
					}
				}
				items[0].children = data
				return items
			},
			
			valueArr(){
				let arr = []
				arr[0] = parseFloat(this.$route.query.id)
				return arr
			}
		},
		methods: {
			// 获取树的数据
			getTree(){
				this.$store.dispatch('user/getUserList')
			},
			// 点击时触发
			onClick(context){
				if(!context.node.data.children){
					this.valueArr[0] = context.node.data.value
					this.$router.push({
						name: 'UserInfo',
						query: {
							id: context.node.data.value
						}
					})
					this.$bus.$emit('getUserData');
				}
			},
		},
		mounted() {
			this.getTree()
		}
	}
</script>

<style>
</style>